package com.iov.fence.service.impl;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.iov.fence.utils.RedisUtil;
import com.iov.fence.vo.FenceVo;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import com.iov.fence.mapper.TbFenceMapper;
import com.iov.fence.domain.TbFence;
import com.iov.fence.service.ITbFenceService;

/**
 * 围栏信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-23
 */
@Service
public class TbFenceServiceImpl implements ITbFenceService 
{
    @Autowired
    private TbFenceMapper tbFenceMapper;

    /**
     * 查询围栏信息
     * 
     * @param id 围栏信息主键
     * @return 围栏信息
     */
    @Override
    public TbFence selectTbFenceById(Long id)
    {
        return tbFenceMapper.selectTbFenceById(id);
    }

    /**
     * 查询围栏信息列表
     * 
     * @param tbFence 围栏信息
     * @return 围栏信息
     */
    @Override
    public List<TbFence> selectTbFenceList(TbFence tbFence)
    {
        return tbFenceMapper.selectTbFenceList(tbFence);
    }

    /**
     * 新增围栏信息
     * 
     * @param tbFence 围栏信息
     * @return 结果
     */
    @Override
    public int insertTbFence(TbFence tbFence)
    {
        return tbFenceMapper.insertTbFence(tbFence);
    }

    /**
     * 修改围栏信息
     * 
     * @param tbFence 围栏信息
     * @return 结果
     */
    @Override
    public int updateTbFence(TbFence tbFence)
    {
        return tbFenceMapper.updateTbFence(tbFence);
    }

    /**
     * 批量删除围栏信息
     * 
     * @param ids 需要删除的围栏信息主键
     * @return 结果
     */
    @Override
    public int deleteTbFenceByIds(Long[] ids)
    {
        return tbFenceMapper.deleteTbFenceByIds(ids);
    }

    /**
     * 删除围栏信息信息
     * 
     * @param id 围栏信息主键
     * @return 结果
     */
    @Override
    public int deleteTbFenceById(Long id)
    {
        return tbFenceMapper.deleteTbFenceById(id);
    }

    @Override
    public int addCoordinate(TbFence tbFence) {
        return tbFenceMapper.addCoordinate(tbFence);
    }

//    @Override
//    public TableDataInfo queryListFailure(FenceVo fenceVo) {
//        List<TbFence> list=null;
//        List<TbFence> tbFences = this.selectTbFenceList(new TbFence());
//        RedisTemplate redis = RedisUtil.redis;
//        ZSetOperations zSetOperations = redis.opsForZSet();
//        Set set = zSetOperations.range("RedisFencd", 0, -1);
//        if(set.isEmpty()){
//            for (TbFence tbFence : tbFences) {
//                zSetOperations.add("RedisFencd",tbFence,tbFence.getId());
//            }
//            set=zSetOperations.range("RedisFencd",0,-1);
//        }
//        Integer startPage=(fenceVo.getPageNum()-1)*fenceVo.getPageSize();
//        Integer endPage=fenceVo.getPageNum()*fenceVo.getPageSize()-1;
//        Set codeList=zSetOperations.range("RedisFencd",startPage,endPage);
//        list=(List<TbFence>)codeList.stream().collect(Collectors.toList());
//        List<TbFence> collect = list.stream().filter(item -> {
//            if (StringUtils.isNotEmpty(fenceVo.getFenceCode())) {
//                return item.getFenceName().equals(fenceVo.getFenceCode()) ? true : false;
//            }
//            return true;
//        }).collect(Collectors.toList());
//        TableDataInfo tableDataInfo = new TableDataInfo();
//        tableDataInfo.setTotal(set.size());
//        tableDataInfo.setCode(200);
//        tableDataInfo.setMsg("查询成功");
//        tableDataInfo.setRows(collect);
//        return tableDataInfo;
//    }
}
